﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace sy2_8
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void btnPrint_Click(object sender, EventArgs e)
        {
            lblResult.Text = "输出结果";
        }

        private void BtnPrint_Click(object sender, EventArgs e)
        {
            string s = txtInput.Text;
            if (s.Length != 1)
            {
                MessageBox.Show("只能输入1个字符！");
                txtInput.Text = "";
                txtInput.Focus();
                return;
            }

            char c = s[0];
            int loopCount, baseNum;

            if (Char.IsNumber(c))
            {
                baseNum = 49; // 数字 '1' 的 ASCII 码是 49
            }
            else if (Char.IsUpper(c))
            {
                baseNum = 65; // 大写字母 'A' 的 ASCII 码是 65
            }
            else if (Char.IsLower(c))
            {
                baseNum = 97; // 小写字母 'a' 的 ASCII 码是 97
            }
            else
            {
                MessageBox.Show("输入的字符不合法，只能是大小写字母或数字1-9！");
                txtInput.Text = "";
                txtInput.Focus();
                return;
            }

            loopCount = c - baseNum + 1;
            lblResult.Text = "";

            for (int i = 0; i < loopCount; i++)
            {
                for (int j = loopCount; j > i + 1; j--)
                {
                    lblResult.Text += " ";
                }
                for (int k = 0; k < 2 * i + 1; k++)
                {
                    lblResult.Text += (char)(baseNum + i);
                }
                lblResult.Text += "\r\n";
            }
        }

        private void btnClear_Click(object sender, EventArgs e)
        {
            
        }

        private void btnClear_Click_1(object sender, EventArgs e)
        {
            txtInput.Text = "";
            lblResult.Text = "输出结果";
        }

        private void lblResult_Click(object sender, EventArgs e)
        {

        }
    }
}
